package short_semester.questionnaire_planet.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import short_semester.questionnaire_planet.entity.User;
import short_semester.questionnaire_planet.pojo.Questionnaire;

import javax.transaction.Transactional;
import java.util.List;

public interface QuestionnaireDao extends JpaRepository<Questionnaire,Integer> {
    List<Questionnaire> findByUser(User user);
    
    @Modifying
    @Transactional
    @Query("update Questionnaire q set q.count=q.count+1 where q.id=:id")
    void submitQuestionnaire(Integer id);

    List<Questionnaire> findByUserAndTitleNotNullAndTitleContainingAndIsDeletedFalse(User user,String title);
    
    Questionnaire findByImg(String arg);

    @Modifying
    @Transactional
    @Query("update Questionnaire q set q.store=q.store-1 where q.id=:id")
    void sign(Integer id);
    
    
}
